ARG GOLANG_IMAGE
ARG NVIDIA_IMAGE
FROM $GOLANG_IMAGE AS build

FROM $GOLANG_IMAGE AS GOBUILD
ADD . /k8s-vgpu
ARG GOPROXY=https://goproxy.cn,direct
RUN apt-get update && apt-get -y install libhwloc-dev libdrm-dev
RUN cd /k8s-vgpu && make all

FROM nvidia/cuda:12.2.0-base-ubuntu22.04
ENV NVIDIA_DISABLE_REQUIRE="true"
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=utility

ARG VERSION
LABEL version="$VERSION"
LABEL maintainer="opensource@4paradigm.com"
COPY ./LICENSE /k8s-vgpu/LICENSE
COPY --from=GOBUILD /k8s-vgpu/bin /k8s-vgpu/bin
COPY ./docker/entrypoint.sh /k8s-vgpu/bin/entrypoint.sh
COPY ./lib /k8s-vgpu/lib
COPY ./lib/mlu/cntopo /usr/bin/
COPY ./lib/mlu/libcndev.so /usr/lib/

ENV PATH="/k8s-vgpu/bin:${PATH}"
ARG DEST_DIR
ENTRYPOINT ["/bin/bash", "-c", "entrypoint.sh  $DEST_DIR"]
